import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home'
import detail from '../views/Detail'
import login from '../views/Login'
import second from '../views/Second'
import nowplaying from '@/views/about/Nowplaying'
import comingsoon from '@/views/about/Comingsoon'

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    component: Home
  },
  {
    path: '/detail/:id', // 动态路由
    component: detail
  },
  {
    path: '/second',
    component: second
  },
  {
    path: '/about',
    component: () => import('../views/About.vue'),
    children: [{
      path: 'nowplaying',
      component: nowplaying
    },
    {
      path: '/about/comingsoon',
      component: comingsoon
    },
    {
      path: '',
      // 重定向
      redirect: '/about/nowplaying'
    }
   ]
  },
  {
    path: '/login',
    component: login
  }
]

const router = new VueRouter({
  mode: 'history', // 如果是history,url中不带#; 如果没有该属性或者为hash,则url中带#
  base: process.env.BASE_URL,
  routes
})
// 全局路由守卫
router.beforeEach((to, from, next) => {
  console.log(to.path)
  if (to.path === '/home'){
    console.log('home ceshi')
    // next('/login')
    next()
  } else {
    next()
  }
})

export default router
